﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using OOAD_Project_Editor.Application;
using OOAD_Project_Editor.Domain;

namespace OOAD_Project_Editor.Presentation
{
    public class PreveiwScreen : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        public IManageSceneHandler ManageSceneHandler { get; private set; }
        public ILoadStoreSceneHandler LoadStoreSceneHandler { get; private set; }

        public PreveiwScreen(IntPtr drawingSurface)
            : this()
        {
            Mouse.WindowHandle = drawingSurface;
            graphics.PreparingDeviceSettings += new EventHandler<PreparingDeviceSettingsEventArgs>(delegate(object sender, PreparingDeviceSettingsEventArgs e)
            {
                e.GraphicsDeviceInformation.PresentationParameters.DeviceWindowHandle = drawingSurface;
            });

            System.Windows.Forms.Form xnaWindow = (System.Windows.Forms.Form)System.Windows.Forms.Control.FromHandle((this.Window.Handle));
            xnaWindow.GotFocus += new EventHandler(delegate(object sender, EventArgs e)
            {
                ((System.Windows.Forms.Form)sender).Visible = false;
            });
        }

        public PreveiwScreen()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            IsMouseVisible = true;
            ManageSceneHandler manageSceneHandler = new ManageSceneHandler(this);
            this.ManageSceneHandler = manageSceneHandler;
            Components.Add(manageSceneHandler);

            LoadStoreSceneHandler loadStoreSceneHandler = new LoadStoreSceneHandler(this);
            this.LoadStoreSceneHandler = loadStoreSceneHandler;
            Components.Add(loadStoreSceneHandler);

        }

        protected override void LoadContent()
        {
            base.LoadContent();
        }

        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();
            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
            base.Draw(gameTime);
        }
    }
}
